#define _CRT_SECURE_NO_WARNINGS 1
#include<stdio.h>
#include<string.h>
#include<stdio.h>
int my_strcmp(char* p1, char* p2)
{
	while (*p1 != '\0' && *p2 != '\0' && *(p1++) == *(p2++));
	if (*(p1 - 1) != *(p2 - 1))
		return *(p1 - 1) - *(p2 - 1);
	else
		return *p1 == '\0' ? -1 : 1;
}
char* my_strstr1(const char* str1, const char* str2)
{
	char* cat = str1;
	while (*cat != '\0')
	{
		int ret=strncmp(cat, str2, strlen(str2));
		if (!ret)
			return cat;
		cat++;
	}
	return NULL;
}
char* my_strstr2(char* str1, char* str2)
{
	char* p1 = NULL;
	char* p2 = NULL;
	char* cat = str1;
	while (*(cat) != '\0')
	{
		p1 = cat;
		p2 = str2;
		while (*p1 != '\0' && *p2 != '\0' && *p1 == *p2)
		{
			p1++;
			p2++;
		}
		if (*p2 == NULL)
			return cat;
		if (*p1 == NULL)
			return NULL;
		cat++;
	}
	return NULL;
}
char* my_strstr3(const char* str1, const char* str2)
{
	for (int i = 0; str1[i]!='\0'; i++)
	{
		int t = i;
		int j = 0;
		while(str2[j]!='\0' && str1[t++] == str2[j++]);
		if (str2[j] == '\0' && str1[t - 1] == str2[j - 1])
			return str1 + i;
	}
	return NULL;
}
int main()
{
	char a[] = "exxxixxituy";
	char b[] = "xi";
	printf("%s\n", my_strstr1(a, b));
	printf("%s\n", my_strstr2(a, b));
	printf("%s\n", my_strstr3(a, b));
	printf("%s\n", strstr(a, b));
	int ret = my_strcmp(a, b);
	if (ret > 0)
		printf("a>b\n");
	else if (ret < 0)
		printf("a<b\n");
	else
		printf("a=b\n");
	return 0;
}
